package com.yanqingshan.platform.module.auth.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.yanqingshan.platform.common.constant.AppConstant;
import com.yanqingshan.platform.common.core.domain.R;
import com.yanqingshan.platform.module.auth.model.domain.UserTokenInfo;
import com.yanqingshan.platform.module.auth.model.dto.AuthLoginReqVO;
import com.yanqingshan.platform.module.sys.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 功能描述: 认证鉴权 前端控制器
 *
 * @author yanqs
 * @since 2023-05-13
 */
@Api(tags = "认证鉴权")
@ApiSupport(order = 1)
@RestController
@RequestMapping(AppConstant.APPLICATION_AUTH)
public class AuthController {

    @Resource
    private SysUserService sysUserService;

    @ApiOperationSupport(order = 1)
    @ApiOperation("登录系统")
    @PostMapping(value = "/login")
    public R<UserTokenInfo> login(@RequestBody @Valid AuthLoginReqVO param) {
        return sysUserService.login(param);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("登出系统")
    @PostMapping("/logout")
    public R logout() {
        StpUtil.logout();
        return R.ok();
    }
}
